package cn.smbms.controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.smbms.pojo.Provider;
import cn.smbms.pojo.User;
import cn.smbms.service.ProviderService;


@Controller
public class ProviderController {
	@Resource
	private ProviderService service;
	
	/**
	 * 查询所有
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/providerlist")
	public String providerlist(HttpServletRequest request) {
		List<Provider> list=service.getProviderList();
		request.setAttribute("providerList", list);
		return "providerlist";
	}
	
	/**
	 * 根据Id查询所有信心
	 */
	@RequestMapping("providerById")
	public String providerById(Integer id,HttpServletRequest request) {
		Provider provider=service.providerById(id);
		
		request.setAttribute("provider", provider);
		return "providerview";
	}
	@RequestMapping("providerExit")
	@ResponseBody
	public Object providerExit(Integer proid) {
		HashMap< String, Object> hashMap=new HashMap<String, Object>();
		if (proid==null) {
			hashMap.put("delResult", "notexist");
		}
		int result=service.providerExit(proid);
		if (result>0) {
			hashMap.put("delResult", "true");
		}else {
			hashMap.put("delResult", "false");
		}
		
		return hashMap;
		
	}
	@RequestMapping("provider")
	public String provider(Integer proid,HttpServletRequest request) {
		Provider provider=service.providerById(proid);
		
		request.setAttribute("provider", provider);
		return "providermodify";
	}
	@RequestMapping("providerupda")
	public String providerupda(Provider provider) {
		
		int result=service.providerupda(provider);
		if (result>0) {
			return "redirect:providerlist";
		}
		return "providermodify";
	}
	@RequestMapping("add")
	public String add() {
		
		return "provideradd";
	}
	
	@RequestMapping("provideradd")
	public String provideradd(Provider provider) {
		int count =service.provideradd(provider);
		if (count>0) {
			return "redirect:providerlist";
		}
		return "provideradd";
	}
}
